const mongoose = require("mongoose")
const deSchema = new mongoose.Schema({
  username:{type:String},
  password:{type:String},
})
const data = mongoose.model("des",deSchema)
module.exports = {
  init(){
    mongoose.connect("mongodb://127.0.0.1:27017/de",{
      useNewUrlParser:true
    }).then(()=>{
      console.log("成功链接")
    }).catch((e)=>{
      console.warn(e);
    })
  },
  async checkUser(username,password){
    const user =await data.findOne({username})
    return user && user.password === password
  },
  async register(username,password){
    //向数据库中插入一条数据
   await data.insertMany([{
      username,
      password
    }])
    return {
      success:true,
      msg:"注册成功"
    }
  }
}